package com.hometeacher.api.service;

import com.hometeacher.api.model.TeacherList;
import com.hometeacher.api.model.User;
import com.hometeacher.api.repository.TeacherListRepository;
import com.hometeacher.api.repository.UsersRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.security.SecureRandom;
import java.util.List;

/**
 * @author ZhaoYuan
 * @data 03/04/2020 21:32
 * user confirm
 */
@Slf4j
@Service
public class TeacherService {
    @Autowired
    TeacherListRepository teacherListRepository;
    @Autowired
    UsersRepository usersRepository;

    public List<TeacherList> findAllTeacherInfo(){
        return teacherListRepository.findAll();
    }

    public TeacherList findByUser(User user) {

        Long uid = usersRepository.findUserByUsername(user.getUsername()).getUid();
        log.info("get uid {}",uid);
        log.info("get  {}",teacherListRepository.findByUid(uid).getCourse());
        return teacherListRepository.findByUid(uid);
    }

    public TeacherList save(TeacherList teacherList){
        return teacherListRepository.save(teacherList);
    }
}
